﻿using System;
using System.Data;
using System.Collections.Generic;

namespace Chenxin.Lib.House.BLL
{
    /// <summary>
    /// 业务逻辑类House_RequestChangeInfo 的摘要说明。
    /// creator:kimi.dev
    /// date:2010-3-2
    /// </summary>
    public class House_RequestChangeInfo
    {
        public House_RequestChangeInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.House.Entity.House_RequestChangeInfo model)
        {
            //1.保存变更请求
            DAL.House_RequestChangeInfo.Add(model);
          
            //2.发送消息通知
            Entity.Notice notice = new Entity.Notice();
            notice.RecordId =  Guid.NewGuid();
            notice.NoticeType = 0;
            notice.Title = "请求变更";
            notice.body	= "[" + model.HouseAddress + "]房源由" + model.Operator + "请求变更。";
            //notice.AttachmentName	
            //notice.AttachmentFileName	
            //notice.AttachmentFilePath	
            //notice.AttachmentFileSize	
            //notice.AttachmentFileType	
            notice.CompanyId = model.CompanyId;
            notice.CompanyName = model.CompanyName;
            notice.SenderId = model.OperatorId;
            notice.DelFlg =0;
            notice.DepartMentId	 = model.OprDepartId;
            notice.SendDate	=DateTime.Now;
            //notice.UpdateDate
            //notice.CityId=
            notice.ReadFlg = 0;
            Chenxin.Lib.House.DAL.Notice.Add(notice);
            //3.写入房源跟单
            //添加跟单记录
           /* Chenxin.Lib.House.Entity.House_TraceInfo house_TraceInfo = new Chenxin.Lib.House.Entity.House_TraceInfo();
            house_TraceInfo.TraceId = Guid.NewGuid();
            //跟单方式	
            house_TraceInfo.TraceType = 0;
            //跟单内容	 
            house_TraceInfo.TraceContext =  model.RequestUser + "请求变更房源。";
            //跟单人Id	 
            house_TraceInfo.TractorId = model.OperatorId;
            //跟单人	 
            house_TraceInfo.Tractor = model.Operator;
            //跟单部门Id	 
            house_TraceInfo.DepartId = model.OprDepartId;
            //跟单部门	 
            house_TraceInfo.Depart = model.OprDepart;
            //房源Id	 
            house_TraceInfo.HouseId = model.HouseId;
            //房源编号	
            house_TraceInfo.HouseCode = model.HouseCode;
            //房源地址	 
            house_TraceInfo.HouseAddress = model.HouseAddress;
            //状态
            house_TraceInfo.status = 0;
            house_TraceInfo.TraceTime = DateTime.Now;
            Chenxin.Lib.House.DAL.House_TraceInfo.Add(house_TraceInfo);
            */
            //4.写入系统操作日志
            //添加日志
            Chenxin.Lib.House.Entity.House_UserLogs userLogs = new Chenxin.Lib.House.Entity.House_UserLogs();
            userLogs.RecordId = Guid.NewGuid();
            userLogs.UserId = model.OperatorId;
            userLogs.UserName = model.Operator;
            userLogs.DepartId = model.OprDepartId;
            userLogs.DepartName = model.OprDepart;
            userLogs.OprType = "请求变更";
            userLogs.OperationContext = "[" + model.HouseAddress + "]房源由" + model.Operator + "请求变更。";
            userLogs.Addtime = DateTime.Now;
            userLogs.Id = model.HouseId;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.House.Entity.House_RequestChangeInfo model)
        {
           
            //1.确认变更请求
            DAL.House_RequestChangeInfo.Update(model);
            //2.发送消息通知
            Entity.Notice notice = new Entity.Notice();
            notice.RecordId =  Guid.NewGuid();
            notice.NoticeType = 0;
            notice.Title = "请求变更";
            notice.body	= "[" + model.HouseAddress + "]房源由" + model.Operator + "请求变更。";
            //notice.AttachmentName	
            //notice.AttachmentFileName	
            //notice.AttachmentFilePath	
            //notice.AttachmentFileSize	
            //notice.AttachmentFileType	
            notice.CompanyId = model.CompanyId;
            notice.CompanyName = model.CompanyName;
            notice.SenderId = model.OperatorId;
            notice.DelFlg =0;
            notice.DepartMentId	 = model.OprDepartId;
            notice.SendDate	=DateTime.Now;
            //notice.UpdateDate
            //notice.CityId=
            notice.ReadFlg = 0;
            Chenxin.Lib.House.DAL.Notice.Add(notice);
            //3.写入房源跟单
           /* //添加跟单记录
            Chenxin.Lib.House.Entity.House_TraceInfo house_TraceInfo = new Chenxin.Lib.House.Entity.House_TraceInfo();
            house_TraceInfo.TraceId = Guid.NewGuid();
            //跟单方式	
            house_TraceInfo.TraceType = 0;
            //跟单内容	 
            house_TraceInfo.TraceContext = "[" + model.HouseAddress + "]房源由" + model.Operator + "确认变更。";
            //跟单人Id	 
            house_TraceInfo.TractorId = model.OperatorId;
            //跟单人	 
            house_TraceInfo.Tractor = model.Operator;
            //跟单部门Id	 
            house_TraceInfo.DepartId = model.OprDepartId;
            //跟单部门	 
            house_TraceInfo.Depart = model.OprDepart;
            //房源Id	 
            house_TraceInfo.HouseId = model.HouseId;
            //房源编号	
            house_TraceInfo.HouseCode = model.HouseCode;
            //房源地址	 
            house_TraceInfo.HouseAddress = model.HouseAddress;
            //状态
            house_TraceInfo.status = 0;
            house_TraceInfo.TraceTime = DateTime.Now;
            Chenxin.Lib.House.DAL.House_TraceInfo.Add(house_TraceInfo);
            */
              //4.写入系统操作日志
            //添加日志
            Chenxin.Lib.House.Entity.House_UserLogs userLogs = new Chenxin.Lib.House.Entity.House_UserLogs();
            userLogs.RecordId = Guid.NewGuid();
            userLogs.UserId = model.OperatorId;
            userLogs.UserName = model.Operator;
            userLogs.DepartId = model.OprDepartId;
            userLogs.DepartName = model.OprDepart;
            userLogs.OprType = "请求变更";
            userLogs.OperationContext = "[" + model.HouseAddress + "]房源由" + model.Operator + "请求变更。";
            userLogs.Addtime = DateTime.Now;
            userLogs.Id = model.HouseId;
        }


        /// <summary>
        /// 库存房源变更
        /// </summary>
        public static void HouseCensorUpdate(Chenxin.Lib.House.Entity.House_RequestChangeInfo model)
        {

            //1.确认变更请求
            //DAL.House_RequestChangeInfo.Update(model);
            //2.发送消息通知
            Entity.Notice notice = new Entity.Notice();
            notice.RecordId = Guid.NewGuid();
            notice.NoticeType = 0;
            notice.Title = "房源变更";
            notice.body = "[" + model.HouseAddress + "]房源由" + model.Operator + "变更。";
            notice.CompanyId = model.CompanyId;
            notice.CompanyName = model.CompanyName;
            notice.SenderId = model.OperatorId;
            notice.DelFlg = 0;
            notice.DepartMentId = model.OprDepartId;
            notice.SendDate = DateTime.Now;
            notice.ReadFlg = 0;
            Chenxin.Lib.House.DAL.Notice.Add(notice);
            //4.写入系统操作日志
            //添加日志
            Chenxin.Lib.House.Entity.House_UserLogs userLogs = new Chenxin.Lib.House.Entity.House_UserLogs();
            userLogs.RecordId = Guid.NewGuid();
            userLogs.UserId = model.OperatorId;
            userLogs.UserName = model.Operator;
            userLogs.DepartId = model.OprDepartId;
            userLogs.DepartName = model.OprDepart;
            userLogs.OprType = "房源变更";
            userLogs.OperationContext = "[" + model.HouseAddress + "]房源由" + model.Operator + "变更。";
            userLogs.Addtime = DateTime.Now;
            userLogs.Id = model.HouseId;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            DAL.House_RequestChangeInfo.Delete(RecordId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.House.Entity.House_RequestChangeInfo GetModel(Guid RecordId)
        {

            return DAL.House_RequestChangeInfo.GetModel(RecordId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return DAL.House_RequestChangeInfo.GetList(strWhere);
        }
        
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.House.Entity.House_RequestChangeInfo> GetModelList(string strWhere)
        {
            DataSet ds = DAL.House_RequestChangeInfo.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.House.Entity.House_RequestChangeInfo> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.House.Entity.House_RequestChangeInfo> modelList = new List<Chenxin.Lib.House.Entity.House_RequestChangeInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.House.Entity.House_RequestChangeInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.House.Entity.House_RequestChangeInfo();
                    if (dt.Rows[n]["RecordId"].ToString() != "")
                    {
                        model.RecordId = new Guid(dt.Rows[n]["RecordId"].ToString());
                    }
                    if (dt.Rows[n]["HouseId"].ToString() != "")
                    {
                        model.HouseId = new Guid(dt.Rows[n]["HouseId"].ToString());
                    }
                    model.HouseCode = dt.Rows[n]["HouseCode"].ToString();
                    model.HouseAddress = dt.Rows[n]["HouseAddress"].ToString();
                    if (dt.Rows[n]["ChangeType"].ToString() != "")
                    {
                        model.ChangeType = int.Parse(dt.Rows[n]["ChangeType"].ToString());
                    }
                    if (dt.Rows[n]["HouseStatus"].ToString() != "")
                    {
                        model.HouseStatus = int.Parse(dt.Rows[n]["HouseStatus"].ToString());
                    }
                    if (dt.Rows[n]["OperatorId"].ToString() != "")
                    {
                        model.OperatorId = new Guid(dt.Rows[n]["OperatorId"].ToString());
                    }
                    model.Operator = dt.Rows[n]["Operator"].ToString();
                    if (dt.Rows[n]["OprDepartId"].ToString() != "")
                    {
                        model.OprDepartId = new Guid(dt.Rows[n]["OprDepartId"].ToString());
                    }
                    model.OprDepart = dt.Rows[n]["OprDepart"].ToString();
                    if (dt.Rows[n]["RequestUserId"].ToString() != "")
                    {
                        model.RequestUserId = new Guid(dt.Rows[n]["RequestUserId"].ToString());
                    }
                    model.RequestUser = dt.Rows[n]["RequestUser"].ToString();
                    model.RequestDepart = dt.Rows[n]["RequestDepart"].ToString();
                    model.Remarks = dt.Rows[n]["Remarks"].ToString();
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = int.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    if (dt.Rows[n]["Addtime"].ToString() != "")
                    {
                        model.Addtime = DateTime.Parse(dt.Rows[n]["Addtime"].ToString());
                    }
                    if (dt.Rows[n]["DealTime"].ToString() != "")
                    {
                        model.DealTime = DateTime.Parse(dt.Rows[n]["DealTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

